package com.fangcang.service;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.springframework.stereotype.Service;

@Service("threadPoolService")
public class ThreadPoolService {

	private ExecutorService taskExecutor = Executors.newFixedThreadPool(100);
	
	public void execute(String key) {
		for(int i=0; i<100; i++) {
			String merchantCode =  "M100000" + i;
			ThreadTask task = new ThreadTask(getKey(key, merchantCode) ,  merchantCode);
			taskExecutor.execute(task);
		}
	}
	
	private String getKey(String key, String merchantCode) {
		return key + ":" + merchantCode;
	}
	
	
	class ThreadTask implements Runnable{
		
		private String key;
		private String merchantCode;

		public String getKey() {
			return key;
		}

		public void setKey(String key) {
			this.key = key;
		}

		public String getMerchantCode() {
			return merchantCode;
		}

		public void setMerchantCode(String merchantCode) {
			this.merchantCode = merchantCode;
		}

		public ThreadTask() {
			
		}
		
		public ThreadTask(String key, String merchantCode) {
			this.key = key;
			this.merchantCode = merchantCode;
		}

		@Override
		public void run() {
			System.out.println(this.key + "-------------" + this.merchantCode);
		}
		
	}
}
